$(function(){
	//添加1份
	$(".addDish1").click(function(){
		var did = $(this).parents("tr").parents("tr").find(".did").text();
		var uid = $("#uid").val();
		var warning = $(this).parents("tr").find(".warning1");
		$.ajax({
			type:"post",
			url:"addDishToBuycart",
			data:{"did":did,"uid":uid,"bnum":1},
			success:function(data){
				if (data === '1') {
					warning.text("添加成功").fadeIn("slow");
					warning.fadeOut("slow");
				}else{
					warning.text("添加失败");
				}
			}
		})
	})
	//添加2份
	$(".addDish2").click(function(){
		var did = $(this).parents("tr").parents("tr").find(".did").text();
		var uid = $("#uid").val();
		var warning = $(this).parents("tr").find(".warning2");
		$.ajax({
			type:"post",
			url:"addDishToBuycart",
			data:{"did":did,"uid":uid,"bnum":2},
			success:function(data){
				if (data === '1') {
					warning.text("添加成功").fadeIn("slow");
					warning.fadeOut("slow");
				}else{
					warning.text("添加失败");
				}
			}
		})
	})
	//添加N份
	$(".addDishn").click(function(){
		var did = $(this).parents("tr").parents("tr").find(".did").text();
		var uid = $("#uid").val();
		var warning = $(this).parents("tr").find(".warning3");
		var bnum = $(this).parents("tr").find(".bnum").val();
		var result=bnum.match(/^[0-9]+$/);
		if (result == null) {
			warning.text("请输入数量");
		}else{
		$.ajax({
			type:"post",
			url:"addDishToBuycart",
			data:{"did":did,"uid":uid,"bnum":bnum},
			success:function(data){
				if (data === '1') {
					warning.text("添加成功").fadeIn("slow");
					warning.fadeOut("slow");
				}else{
					warning.text("添加失败");
				}
			}
		})
		}
	})
	
})